package com.xujie.common.utils;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.util.Date;

/**
 * @author Xujie
 * @since 2024/12/21 00:59
 **/


public class DateUtils {
	public static String todayString(int i) {
		DateTime now = DateTime.now();
		DateTime dateTime = now.plusDays(i);
		return dateTime.toString("yyyy-MM-dd");
	}

	public static void main(String[] args) {
		System.out.println(today(0, "10:00"));
	}

	public static Date today(int i, String hours) {
		DateTime now = DateTime.now();
		DateTime dateTime = now.plusDays(i);

		// 创建日期时间字符串
		String s = dateTime.toString("yyyy-MM-dd") + " " + hours;

		// 定义解析格式
		DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm");

		// 使用指定格式解析字符串
		return DateTime.parse(s, formatter).toDate();
	}

	public static Date getStartOfDay(Date dataDate) {
		DateTime dateTime = new DateTime(dataDate);
		return dateTime.withTimeAtStartOfDay().toDate();
	}
}
